﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class shop_U : FormBase1
    {
        public delegate void DoAction();//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        private SVC.client.shop fz = null;
        public shop_U(SVC.client.shop _fz)
        {
            InitializeComponent();
            fz = _fz;
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            valildbefore();
            if (dxValidationProvider1.Validate())
            {
                SVC.client.shop fz = new SVC.client.shop();
                fz.shopcode = te_shopid.Text;
                fz.name = te_shopname.Text;
                fz.address = te_address.Text;
                fz.bank = te_bank.Text;
                fz.bankaccno = te_bankaccno.Text;
                fz.code = te_code.Text;
                fz.legalrep = te_legalrep.Text;
                fz.phone = te_phone.Text;
                fz.remarks = te_remarks.Text;
                fz.taxno = te_tax.Text;
                string result = my.bw.shop_Update(fz, my.ACID);
                if(string.IsNullOrWhiteSpace(result))
                {
                    FatherRefresh();
                    this.Close();
                }
                else
                {
                    Comm.ShowErorr(result);
                }
            }
        }

        private void valildbefore()
        {
            te_shopid.Text = te_shopid.Text;
            te_shopname.Text = te_shopname.Text.Trim();
            te_address.Text = te_address.Text.Trim();
            te_bank.Text = te_bank.Text.Trim();
            te_bankaccno.Text = te_bankaccno.Text.Trim();
            te_code.Text = te_code.Text.Trim();
            te_legalrep.Text = te_legalrep.Text.Trim();
            te_phone.Text = te_phone.Text.Trim();
            te_remarks.Text = te_remarks.Text.Trim();
            te_tax.Text = te_tax.Text.Trim();
        }


        private void load()
        {
            te_shopid.Text = fz.shopcode;
            te_shopname.Text = fz.name;
            te_address.Text = fz.address;
            te_bank.Text = fz.bank;
            te_bankaccno.Text = fz.bankaccno;
            te_code.Text = fz.code;
            te_legalrep.Text = fz.legalrep;
            te_phone.Text = fz.phone;
            te_remarks.Text = fz.remarks;
            te_tax.Text = fz.taxno;
        }

        private void shop_U_Load(object sender, EventArgs e)
        {
            load();
        }

    }
}